﻿$(document).ready(function() {
    $(".spnNote").click(function() {
        var idCL = $("#" + txtCLNumber).val();
        var thisval = $(this).closest('li').children('input:hidden').val();

        var sendData = {
            "IDReq": idCL,
            "IDApv": thisval
        }
        $.ajax({
            type: "POST",
            url: 'ViewRequest.aspx/ViewNotes',
            data: JSON.stringify(sendData),
            contentType: "application/json;charset=utf-8",
            datatype: "json",
            success: function(data) {
                var result = data.d;
                if (result[0] == 1) {
                    showNote(result[1], result[2]);
                }
            }
        });
        return false;
    });

    $("#ModalDialog").on("click", "#btnSaveApp", function() {
        var sendData = {
            "IDCL": $("#" + txtCLNumber).val(),
            "ApvStatus": $("#cbAppAct").val(),
            "ApvNotes": $("#txtAppNote").val()
        };
        $.ajax({
            type: "POST",
            url: "BulkView.aspx/SetApproval",
            data: JSON.stringify(sendData),
            contentType: "application/json;charset=utf-8",
            datatype: "json",
            success: function(data) {
                var result = data.d;
                alert(result.Response);
                window.location.href = "Home.aspx";
            },
            beforeSend: function(jqXHR, setting) {
                $("#errBox").text("Processing, please wait...");
                $("#btnSaveApp").hide();
            },
            error: function(jqXHR, statusText, errorText) {
                alert(errorText);
                window.location.href = "Home.aspx";
            }
        });
        return false;
    });

    $("#btnApprove").click(function(e) {
        e.preventDefault();
        var idCL = $("#" + txtCLNumber).val();
        showApp(idCL);
    });
});
function showNote(apvName, apvNote) {
    var txtTitle = 'Notes from:<br /><span style="color:Blue;">' + apvName + '</span>';
    var txtBody = '<p>' + apvNote + '</p>';

    var dTitle = '<div style="border-bottom:1px dotted #000;padding:5px 0;font-size:12px;' +
        'font-weight:bold;margin:10px;text-align:center;font-family:Arial;color:Red;">' +
        txtTitle + '</div>';
    var dContent = '<div style="font-size:14px;padding:0;margin:0 10px;color:#8C008C;">' +
        txtBody + '</div>';
    var dButton = '<div id="divClose" style="position:absolute;bottom:10px;left:0;width:100%;text-align:center;">' +
        '<div id="btnClose" class="btnSmall" title="OK" style="padding:3px 21px;">OK</div>' +
        '</div>';

    var noteContent = dTitle + dContent + dButton;
    $('#ModalDialog').html(noteContent).showCZDialog({
        width: 360, height: 290, closeButton: '#btnClose'
    });
    $('#divModalWrap').css("background", "#FFF");
}
function showApp(idCL) {
    var txtTitle = 'Set Approval Status:<br /><span style="color:Blue;">' + idCL + '</span>';
    var txtBody = '<div style="margin-top:15px;">';
    txtBody += '<span style="font-size:12px;margin-left:10px;">Status:</span>';
    txtBody += '<select name="cbAppAct" id="cbAppAct" style="font-size:12px;margin-left:5px;width:201px;">';
    txtBody += '<option value="1">Approve</option>';
    txtBody += '<option value="2">Return for Information</option>';
    txtBody += '<option value="3">Reject</option>';
    txtBody += '</select>';
    txtBody += '<div style="font-size:12px;margin:5px 0 5px 10px;">Notes:</div>';
    txtBody += '<textarea name="txtAppNote" id="txtAppNote" cols="28" rows="3" ' +
        'style="font-size:12px;margin-left:10px;width:236px;" maxlength="225"></textarea>';
    txtBody += '</div></div>';

    var dTitle = '<div style="border-bottom:1px dotted #000;padding:5px 0;font-size:12px;' +
        'font-weight:bold;margin:10px;text-align:center;font-family:Arial;color:Red;">' +
        txtTitle + '</div>';
    var dContent = '<div style="font-size:14px;padding:0;margin:0 10px;color:#8C008C;">' +
        txtBody + '</div>';
    var dButton = '<div id="divClose" style="position:absolute;bottom:15px;left:0;width:100%;' +
        'text-align:center;">' +
        '<div id="btnCancelApp" class="btnSmall" title="Cancel" style="padding:3px 21px;margin-right:10px;">Cancel</div>' +
        '<div id="btnSaveApp" class="btnSmall" title="Update" style="padding:3px 21px;">Update</div>' +
        '</div>';

    var errMsg = '<div id="errBox" style="margin:10px 0;text-align:center;color:Red;font-size:12px;"></div>';
    var noteContent = dTitle + dContent + errMsg + dButton;
    $('#ModalDialog').html(noteContent).showCZDialog({
        width: 300, height: 300, closeButton: '#btnCancelApp'
    });
    $('#divModalWrap').css("background", "#FFF");
}